<html>

<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name="Author" content="Public domain">
<title>Qucs - Getting Started with Optimization</title>
</head>

<body>
<a name="top" id="top"></a>

<center><h3>
- Qucs -<br>
Quite Universal Circuit Simulator<br>
</h3>
<h1>
Getting Started with<br>
Optimization<br><br>
</h1></center>

For circuit optimization, Qucs uses the ASCO tool
(<a href="http://asco.sourceforge.net/">http://asco.sourceforge.net/</a>). A
brief description on how to prepare your schematic, execute and interprete the
results is given below. Before using this functionality, ASCO must be installed
on the computer.
<br><br>

Optimization of a circuit is nothing more than the minimization of a cost
function. It can either be the delay or the rise time of a digital circuit, or
the power or gain of an analog circuit. Another possibility is defining the
optimization problem as a composition of functions, leading in this case to the
definition of a figure-of-merit.
<br><br>

To setup a netlist for optimization two things must be added to the already
existing netlist: insert equation(s) and the optimization component block. Take
the schematic from Figure 1 and change it until you have the resulting schematic
given in Figure 2.
<br><br>

<center>
<img src="optimization1.png"><br>Figure 1 - Initial schematic.<br><br>
</center>

<center>
<img src="optimization2.png"><br>Figure 2 - Prepared schematic.<br><br>
</center>

<br>
Now, open the optimization component and select the optimization tab. From the
existing parameters, special attention should be paid to 'Maximum number of
iterations', 'Constant F' and 'Crossing over factor'. Over- or underestimation
can lead to a premature convergence of the optimizer to a local minimum or, a very long
optimization time.
<br><br>

<center>
<img src="optimization3.png"><br>Figure 3 - Optimization dialog, algorithm options.<br><br>
</center>

<br>
In the Variables tab, defining which circuit elements will be chosen from the
allowed range, as shown in Figure 4.  The variable names correspond to the
identifiers placed into properties of components and <b>not</b> the components'
names.
<br><br>

<center>
<img src="optimization4.png"><br>Figure 4 - Optimization dialog, variables options.<br><br>
</center>

<br>
Finally, go to Goals where the optimization objective (maximize, minimize) and
constraints (less, greater, equal) are defined. ASCO then automatically combines
them into a single cost function, that is then minimized.
<br><br>

<center>
<img src="optimization5.png"><br>Figure 5 - Optimization dialog, goals options.<br><br>
</center>

<br>
The next step is to change the schematic, and define which circuit elements are
to be optimized. The resulting schematic is show in Figure 6.
<br><br>

<center>
<img src="optimization6.png"><br>Figure 6 - New Qucs main window.<br><br>
</center>

<br>
The last step is to run the optimization, i.e. the simulation by pressing F2.
Once finished, which takes a few
seconds on a modern computer, the best simulation results is shown in the
graphical waveform viewer. 
<br><br>

<center>
<img src="optimization7.png"><br>Figure 7 - Qucs results window.<br><br>
</center>

The best found circuit sizes can be found in the optimization dialog, in the
Variables tab. They are now the initial values for each one of introduced
variables (Figure 8).
<br><br>

<center>
<img src="optimization8.png"><br>Figure 8 - The best found circuit sizes.<br><br>
</center>

By clicking the "Copy current values to equation" button, an equation component defining all the optimization variables with the values of the "initial" column will be copied to the clipboard and can be pasted to the schematic after closing the optimization dialog.
<br>
The resulting schematic will be as shown in the next figure.
<br><br>

<center>
<img src="optimization9.png"><br>Figure 9 - Schematic with optimized values.<br><br>
</center>

in case you need to do further modifications to the schematic, the optimization component can now be disabled and the optimized values from the pasted equation will be used.

<br><br>
You can change the number of figures shown for the optimized values in the optimization dialog by right-clicking on the "initial" table header and selecting the "Set precision" menu, as shown in the following figure.
<br><br>

<center>
<img src="optimization10.png"><br>Figure 10 - Changing the displayed variables precision.<br><br>
</center>

<br><br><a href="#top">back to the top</a><br>
</body>
</html>
